package com.yc.anno;

import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.util.Arrays;

@TableName(value = "tbl_user",type = "abc")
public class Demo2 {
    int a;
    @Init("abc")
    void test(){}

    public static void main(String[] args) throws NoSuchMethodException {
        TableName tableName = Demo2.class.getAnnotation(TableName.class);
        System.out.println("tableName.value() = " + tableName.value());
        System.out.println("Arrays.toString(tableName.type()) = " + Arrays.toString(tableName.type()));
        System.out.println("==========================");
        tableName = SubDemo2.class.getAnnotation(TableName.class);
        System.out.println("tableName.value() = " + tableName.value());
        System.out.println("Arrays.toString(tableName.type()) = " + Arrays.toString(tableName.type()));
        System.out.println("==========================");
        Class<? super SubDemo2> demo2Class = SubDemo2.class.getSuperclass();
        Method test = demo2Class.getDeclaredMethod("test");
        Init init = test.getAnnotation(Init.class);
        System.out.println("init.value() = " + init.value());

    }
}

//@TableName(value = "tbl_test",type = "efg")
class SubDemo2 extends Demo2{

}

@Target(value={ElementType.TYPE})
// 运行时有效
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface TableName{
    String value() default "";
    String[] type() default "";
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Init{
    String value();
}


